home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / PInterfaces / CodeFragments.p < prev    next >
Encoding:
Text File  |  1994-07-21  |  6.8 KB  |  225 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        CodeFragments.p
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.1  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16.  
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT CodeFragments;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __CODEFRAGMENTS__}
  27. {$SETC __CODEFRAGMENTS__ := 1}
  28.  
  29. {$I+}
  30. {$SETC CodeFragmentsIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33.  
  34. {$IFC UNDEFINED __TYPES__}
  35. {$I Types.p}
  36. {$ENDC}
  37. {    ConditionalMacros.p                                            }
  38.  
  39. {$IFC UNDEFINED __FILES__}
  40. {$I Files.p}
  41. {$ENDC}
  42. {    MixedMode.p                                                    }
  43. {    OSUtils.p                                                    }
  44.  
  45. {$IFC UNDEFINED __TRAPS__}
  46. {$I Traps.p}
  47. {$ENDC}
  48.  
  49. {$PUSH}
  50. {$ALIGN MAC68K}
  51. {$LibExport+}
  52.     
  53. TYPE
  54. ConnectionID = LONGINT;
  55.  
  56.     LoadFlags = LONGINT;
  57.  
  58.     SymClass = CHAR;
  59.  
  60.  
  61. CONST
  62.     kPowerPCArch                = 'pwpc';                        { use as the architecture type }
  63.     kMotorola68KArch            = 'm68k';                        { use as the architecture type }
  64.     kAnyArchType                = $3f3f3f3f;
  65. { Confusing names, soon to be removed! }
  66.     kPowerPC                    = 'pwpc';                        { use as the architecture type }
  67.     kMotorola68K                = 'm68k';                        { use as the architecture type }
  68.     kNoLibName                    = 0;
  69.     kNoConnectionID                = 0;
  70.     kUnresolvedSymbolAddress    = 0;
  71.  
  72. { Constants used for findFlags mask }
  73.     kLoadLib                    = 1;                            { use existing connection if possible }
  74.     kFindLib                    = 2;                            { just see if library is already loaded }
  75.     kLoadNewCopy                = 5;                            { load a new instance no matter what }
  76.     kUseInPlace                    = $80;                            { use container’s sections in place }
  77.  
  78.     kCodeSym                    = 0;
  79.     kDataSym                    = 1;
  80.     kTVectSym                    = 2;
  81.     kTOCSym                        = 3;
  82.     kGlueSym                    = 4;
  83.  
  84. {    Constants for the FragmentLocator field .where (other values for this enum exist) }
  85.     kInMem                        = 0;
  86.     kOnDiskFlat                    = 1;
  87.     kOnDiskSegmented            = 2;
  88.  
  89.     kIsLib                        = 0;
  90.     kIsApp                        = 1;
  91.     kIsDropIn                    = 2;
  92.  
  93. {    Constants for the 'cfrg' field .updateLevel }
  94.     kFullLib                    = 0;
  95.     kUpdateLib                    = 1;
  96.  
  97. { For fragment initialization routines }
  98.  
  99. TYPE
  100.     MemFragment = RECORD
  101.         address:                Ptr;
  102.         length:                    LONGINT;
  103.         inPlace:                BOOLEAN;
  104.         spare3a:                ARRAY [0..2] OF CHAR;
  105.     END;
  106.     DiskFragment = RECORD
  107.         fileSpec:                FSSpecPtr;                                { Must correspond to FSSpecPtr in segmented case }
  108.         offset:                    LONGINT;
  109.         length:                    LONGINT;
  110.     END;
  111.     SegmentedFragment = RECORD
  112.         fileSpec:                FSSpecPtr;                                { Must correspond to FSSpecPtr in data fork case }
  113.         rsrcType:                OSType;
  114.         rsrcID:                    INTEGER;
  115.     END;
  116. { Note that the onDisk and inSegs members are required to have an FSSpecPtr
  117.  field at the same location.  CFM code uses just one member to access the
  118.  information for either case }
  119.     FragmentLocator = RECORD
  120.         where:                    LONGINT;
  121.         CASE INTEGER OF
  122.         0: (
  123.             inMem:                        MemFragment;
  124.            );
  125.         1: (
  126.             onDisk:                        DiskFragment;
  127.            );
  128.         2: (
  129.             inSegs:                        SegmentedFragment;
  130.            );
  131.     END;
  132.  
  133.     FragmentLocatorPtr = ^FragmentLocator;
  134.  
  135. { NOTE: when fragLocator. where == kOnDisk, then
  136.        fragLocator. u. onDisk. fileSpec is a pointer
  137.        to the file that the library belonged to.
  138.        the pointer is valid only for the duration
  139.        of the init routine's invocation, so make
  140.        a copy of the filespec if it is important }
  141.     InitBlock = RECORD
  142.         contextID:                LONGINT;
  143.         closureID:                LONGINT;
  144.         connectionID:            LONGINT;
  145.         fragLocator:            FragmentLocator;
  146.         libName:                Ptr;
  147.         reserved4a:                LONGINT;
  148.         reserved4b:                LONGINT;
  149.         reserved4c:                LONGINT;
  150.         reserved4d:                LONGINT;
  151.     END;
  152.     InitBlockPtr = ^InitBlock;
  153.  
  154. { Prototype for initialization routines.  Note that these are C, not Pascal conventions!
  155.  This differs from customary “Apple-callback” useage, but is felt to be less error prone
  156.  in practice since the vast bulk of 68K CFM aware code will be in C.
  157.  NOTE: Initialization routines may comfortably ignore their parameters, however, they must
  158.  return an error status (ie: noErr) in order to succeed with the load of the library.
  159.  Termination routines get no parameters and have no return value. }
  160.     ConnectionInitializationRoutine = ProcPtr;  { FUNCTION (initBlkPtr: InitBlockPtr): OSErr; }
  161.  
  162.     ConnectionTerminationRoutine = ProcPtr;  { PROCEDURE ; }
  163.  
  164. { Constants used in building shared libraries }
  165.  
  166. CONST
  167.     kCFMRsrcType                = 'cfrg';
  168.     kCFMRsrcID                    = 0;
  169.     kSHLBFileType                = 'shlb';
  170.  
  171. {$IFC UNDEFINED TurnOff68KCFMTraps }
  172. {$SETC TurnOff68KCFMTraps := 0}
  173. {$ENDC}
  174. {$IFC TurnOff68KCFMTraps }
  175.  
  176. FUNCTION GetSharedLibrary(VAR libName: Str63; archType: OSType; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  177. FUNCTION GetDiskFragment(fileSpec: FSSpec; offset: LONGINT; length: LONGINT; VAR fragName: Str63; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  178. FUNCTION GetMemFragment(memAddr: UNIV Ptr; length: LONGINT; VAR fragName: Str63; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  179. FUNCTION CloseConnection(VAR connID: ConnectionID): OSErr;
  180. FUNCTION FindSymbol(connID: ConnectionID; VAR symName: Str255; VAR symAddr: Ptr; VAR symClass: SymClass): OSErr;
  181. FUNCTION CountSymbols(connID: ConnectionID; VAR symCount: LONGINT): OSErr;
  182. FUNCTION GetIndSymbol(connID: ConnectionID; symIndex: LONGINT; VAR symName: Str255; VAR symAddr: Ptr; VAR symClass: SymClass): OSErr;
  183. {$ELSEC}
  184.  
  185. FUNCTION GetSharedLibrary(VAR libName: Str63; archType: OSType; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  186.     {$IFC NOT GENERATINGCFM}
  187.     INLINE $3F3C, 1, $AA5A;
  188.     {$ENDC}
  189. FUNCTION GetDiskFragment(fileSpec: FSSpec; offset: LONGINT; length: LONGINT; VAR fragName: Str63; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  190.     {$IFC NOT GENERATINGCFM}
  191.     INLINE $3F3C, 2, $AA5A;
  192.     {$ENDC}
  193. FUNCTION GetMemFragment(memAddr: UNIV Ptr; length: LONGINT; VAR fragName: Str63; findFlags: LoadFlags; VAR connID: ConnectionID; VAR mainAddr: Ptr; VAR errName: Str255): OSErr;
  194.     {$IFC NOT GENERATINGCFM}
  195.     INLINE $3F3C, 3, $AA5A;
  196.     {$ENDC}
  197. FUNCTION CloseConnection(VAR connID: ConnectionID): OSErr;
  198.     {$IFC NOT GENERATINGCFM}
  199.     INLINE $3F3C, 4, $AA5A;
  200.     {$ENDC}
  201. FUNCTION FindSymbol(connID: ConnectionID; VAR symName: Str255; VAR symAddr: Ptr; VAR symClass: SymClass): OSErr;
  202.     {$IFC NOT GENERATINGCFM}
  203.     INLINE $3F3C, 5, $AA5A;
  204.     {$ENDC}
  205. FUNCTION CountSymbols(connID: ConnectionID; VAR symCount: LONGINT): OSErr;
  206.     {$IFC NOT GENERATINGCFM}
  207.     INLINE $3F3C, 6, $AA5A;
  208.     {$ENDC}
  209. FUNCTION GetIndSymbol(connID: ConnectionID; symIndex: LONGINT; VAR symName: Str255; VAR symAddr: Ptr; VAR symClass: SymClass): OSErr;
  210.     {$IFC NOT GENERATINGCFM}
  211.     INLINE $3F3C, 7, $AA5A;
  212.     {$ENDC}
  213. {$ENDC}
  214.  
  215. {$ALIGN RESET}
  216. {$POP}
  217.  
  218. {$SETC UsingIncludes := CodeFragmentsIncludes}
  219.  
  220. {$ENDC} {__CODEFRAGMENTS__}
  221.  
  222. {$IFC NOT UsingIncludes}
  223.  END.
  224. {$ENDC}
  225.